﻿using Microsoft.Xna.Framework.Input;

namespace ZombieGame
{
    public static class InputHandler
    {
        public static KeyboardState LastKeyState;
        public static MouseState LastMouseState;
        public static KeyboardState CurrentKeyState;
        public static MouseState CurrentMouseState;

        public static void Update()
        {
            if (LastKeyState == null)
                LastKeyState = new KeyboardState();
            if (LastMouseState == null)
                LastMouseState = new MouseState();
            LastKeyState = CurrentKeyState;
            LastMouseState = CurrentMouseState;
            CurrentKeyState = Keyboard.GetState();
            CurrentMouseState = Mouse.GetState();
        }

        public static bool IsDown(Keys k)
        {
            return CurrentKeyState[k] == KeyState.Down;
        }

        public static bool IsUp(Keys k)
        {
            return CurrentKeyState[k] == KeyState.Up;
        }

        public static bool IsNewUp(Keys k)
        {
            return CurrentKeyState[k] == KeyState.Up && LastKeyState[k] == KeyState.Down;
        }

        public static bool IsNewDown(Keys k)
        {
            return CurrentKeyState[k] == KeyState.Down && LastKeyState[k] == KeyState.Up;
        }

        public static bool AreSame(Keys k)
        {
            return CurrentKeyState[k] == LastKeyState[k];
        }

        public static bool AreBothDown(Keys k)
        {
            return CurrentKeyState[k] == LastKeyState[k] && CurrentKeyState[k] == KeyState.Down;
        }

        public static bool AreBothUp(Keys k)
        {
            return CurrentKeyState[k] == LastKeyState[k] && CurrentKeyState[k] == KeyState.Up;
        }

        public static bool MouseLPress()
        {
            return CurrentMouseState.LeftButton == ButtonState.Pressed && LastMouseState.LeftButton == ButtonState.Released;
        }

        public static bool MouseLRelease()
        {
            return CurrentMouseState.LeftButton == ButtonState.Released && LastMouseState.LeftButton == ButtonState.Pressed;
        }

        public static bool MouseLSame()
        {
            return CurrentMouseState.LeftButton == LastMouseState.LeftButton;
        }

        public static bool BothLPressed()
        {
            return CurrentMouseState.LeftButton == LastMouseState.LeftButton && CurrentMouseState.LeftButton == ButtonState.Pressed;
        }

        public static bool BothLReleased()
        {
            return CurrentMouseState.LeftButton == LastMouseState.LeftButton && CurrentMouseState.LeftButton == ButtonState.Released;
        }

        public static bool MouseRPress()
        {
            return CurrentMouseState.RightButton == ButtonState.Pressed && LastMouseState.RightButton == ButtonState.Released;
        }

        public static bool MouseRRelease()
        {
            return CurrentMouseState.RightButton == ButtonState.Released && LastMouseState.RightButton == ButtonState.Pressed;
        }

        public static bool MouseRSame()
        {
            return CurrentMouseState.RightButton == LastMouseState.RightButton;
        }

        public static bool BothRPressed()
        {
            return CurrentMouseState.RightButton == LastMouseState.RightButton && CurrentMouseState.RightButton == ButtonState.Pressed;
        }

        public static bool BothRReleased()
        {
            return CurrentMouseState.RightButton == LastMouseState.RightButton && CurrentMouseState.RightButton == ButtonState.Released;
        }
    }
}
